
package com.jf.cloud.service.sysmanager.remote;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.jf.cloud.service.sysmanager.dao.IPubgUserTeamService;
import com.jf.cloud.service.sysmanager.common.base.AjaxPageData;
import com.jf.cloud.service.sysmanager.common.base.OPaging;
import com.jf.cloud.service.sysmanager.entity.PubgUserTeam;
import com.jf.cloud.service.sysmanager.support.web.BaseController;

/**
 * 员工控制器
 * 
 * @author 代码机1.0 创建时间：2018-03-31
 */
@Controller
@RequestMapping("/pubgUserTeam")
public class PubgUserTeamController extends BaseController {

	/**
	 * 日志
	 */
	private static Log log = LogFactory.getLog(PubgUserTeamController.class);

	/**
	 * 员工服务
	 */
	@Resource
	private IPubgUserTeamService pubgUserTeamService;

	/**
	 * 员工列表数据
	 * 
	 * @author 代码机1.0 创建时间：2018-03-31
	 */
	@RequestMapping(params = "method=data.json")
	public AjaxPageData<PubgUserTeam> listPubgUserTeamData(OPaging<PubgUserTeam> page, HttpServletRequest request) {
		AjaxPageData<PubgUserTeam> dataPage = new AjaxPageData<PubgUserTeam>();
		try {
			dataPage = getAjaxPageData(pubgUserTeamService.findPage(page));
		} catch (Exception e) {
			log.error("获取员工列表数据出错！", e);
		}
		return dataPage;
	}

	/**
	 * 员工列表页面
	 * 
	 * @author 代码机1.0 创建时间：2018-03-31
	 */
	@RequestMapping(params = "method=listPubgUserTeam")
	public String listPubgUserTeam(HttpServletRequest request) {
		
		return "/pubgUserTeamList";
	}

	/**
	 * 员工新增页面
	 * 
	 * @author 代码机1.0 创建时间：2018-03-31
	 */
	@RequestMapping(params = "method=toAddPubgUserTeam")
	public ModelAndView toAddPubgUserTeam() {
		ModelAndView mv = new ModelAndView();
		try {
			PubgUserTeam pubgUserTeam = new PubgUserTeam();
			mv.addObject("pubgUserTeam", pubgUserTeam);

			mv.setViewName("/pubgUserTeamEdit");
		} catch (Exception e) {
			log.error("获取员工新增页面出错！", e);
			mv.setViewName("../exception");
		}
		return mv;
	}

	/**
	 * 新增员工
	 * 
	 * @author 代码机1.0 创建时间：2018-03-31
	 */
	@RequestMapping(params = "method=addPubgUserTeam")
	public String addPubgUserTeam(PubgUserTeam pubgUserTeam, HttpServletRequest request) {
		String errCode = "&errCode=1";
		try {
			this.pubgUserTeamService.saveOrUpdatePubgUserTeam(pubgUserTeam);
		} catch (Exception e) {
			errCode = "&errCode=-1";
			log.error("新增员工出错！", e);
		}
		return "redirect:pubgUserTeam.do?method=listPubgUserTeam" + errCode;
	}

	/**
	 * 员工修改页面
	 * 
	 * @author 代码机1.0 创建时间：2018-03-31
	 */
	@RequestMapping(params = "method=toUpdatePubgUserTeam")
	public ModelAndView toUpdatePubgUserTeam(Long rowId, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		try {
			PubgUserTeam pubgUserTeam = pubgUserTeamService.findPubgUserTeam(rowId);
			mv.addObject("pubgUserTeam", pubgUserTeam);

			mv.setViewName("/pubgUserTeamEdit");
		} catch (Exception e) {
			log.error("获取员工修改页面出错！", e);
			mv.setViewName("../exception");
		}
		return mv;
	}

	/**
	 * 修改员工
	 * 
	 * @author 代码机1.0 创建时间：2018-03-31
	 */
	@RequestMapping(params = "method=updatePubgUserTeam")
	public String updatePubgUserTeam(PubgUserTeam pubgUserTeam, HttpServletRequest request) {
		String errCode = "&errCode=2";
		try {
			this.pubgUserTeamService.saveOrUpdatePubgUserTeam(pubgUserTeam);
		} catch (Exception e) {
			errCode = "&errCode=-2";
			log.error("修改员工出错！", e);
		}
		return "redirect:pubgUserTeam.do?method=listPubgUserTeam" + errCode;
	}

	/**
	 * 员工查看页面
	 * 
	 * @author 代码机1.0 创建时间：2018-03-31
	 */
	@RequestMapping(params = "method=toViewPubgUserTeam")
	public ModelAndView toViewPubgUserTeam(Long rowId, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		try {
			PubgUserTeam pubgUserTeam = pubgUserTeamService.findPubgUserTeam(rowId);
			mv.addObject("pubgUserTeam", pubgUserTeam);

			mv.setViewName("/pubgUserTeamView");
		} catch (Exception e) {
			log.error("获取员工查看页面出错！", e);
			mv.setViewName("../exception");
		}
		return mv;
	}

}
